package com.e3.template.tgf;

import java.util.List;
import java.util.Map;

import com.e3.web.core.model.SuperModel;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;

public abstract class TGFColumnsFormPanel<D extends SuperModel> extends TGFFormPanel<D> {
	
	private FormPanel formPanel;
		
	@Override
	protected void onRender(Element parent, int index) {
		super.onRender(parent, index);
		this.setLayout(new FitLayout());
		this.add(getFormPanel());
	}

	private FormPanel getFormPanel() {
		if(formPanel == null){
			Map<Integer,List<Field<?>>> fields = getFormFields();
			formPanel = createSingleFormPanel();
			initFormPanel(formPanel,fields);
		}
		return formPanel;
	}	
	
//	protected void initColumnsFormPanel(FormPanel fp,List<TGFFormModel> formModels){
//				
//		LayoutContainer main = new LayoutContainer();
//		main.setLayout(new ColumnLayout());
//		
//		int size = formModels.size();
//		for (TGFFormModel tgfFormModel : formModels) {
//			
//			List<Field<?>> fields = tgfFormModel.getFields();
//			if(fields.size()==1){
//				fp.add(fields.get(0));
//				continue;
//			}
//			
//			LayoutContainer lc = new LayoutContainer();
//			//lc.setStyleAttribute("paddingRight", "10px");
//			FormLayout layout = new FormLayout();
//			layout.setLabelAlign(LabelAlign.LEFT);
//			lc.setLayout(layout);
//			
//			for (Field<?> field : fields) {
//				lc.add(field,getFormData());
//			}
//			
//			main.add(lc,new ColumnData(1/size));
//		}
//		
//		fp.add(main);
//		
//	}
	
	public void clearFormData(){
		getFormPanel().clear();
	}
	
	public abstract Map<Integer,List<Field<?>>> getFormFields();

}
